#include "vl_args.h"

using namespace VL;


/**
 * @Author: CimZzz
 * @Date: 2022-06-22 16:56:17
 * 
 * 有参构造函数
 * @param argc 参数数量
 * @param argv 参数值数组
 */
VLArgs::VLArgs(int argc, const char ** argv) {
	this->argc = argc;
	this->argv = argv;
	// 跳过第一个参数, 参数为当前可执行文件目录
	this->currentIdx = 0;
	this->fullyCommand = "";
	for(int i = 1 ; i < argc ; i ++) {
		if(i == 1) {
			this->fullyCommand += argv[i];
		} else {
			this->fullyCommand += " ";
			this->fullyCommand += argv[i];
		}
	}
}

/**
 * @Author: CimZzz
 * @Date: 2022-06-22 18:39:45
 * 
 * 是否全部读完参数
 * @return 如果已经读到末尾返回 true
 */
bool VLArgs::isEnd() {
	return this->currentIdx == this->argc - 1;
}

/**
 * @Author: CimZzz
 * @Date: 2022-06-22 16:56:51
 * 
 * 获取下一个参数
 * @return 下一个参数值
 */
std::string VLArgs::nextParam() {
	if(this->currentIdx == this->argc - 1) {
		return std::string("");
	}
	this->currentIdx ++;
	return std::string(this->argv[this->currentIdx]);
}

/**
 * @Author: CimZzz
 * @Date: 2022-06-22 16:57:30
 * 
 * 向前进一个参数
 */
void VLArgs::forward() {
	if(this->currentIdx == 0) {
		return;
	}
	this->currentIdx --;
}


/**
 * @Author: CimZzz
 * @Date: 2022-06-22 17:07:22
 * 
 * 获取全指令
 * @return 全指令
 */
const std::string& VLArgs::getFullyCommand() {
	return this->fullyCommand;
}